package com.error;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Auther: zwg
 * @Date: 2019/3/5 09:07
 * @Description:
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    private final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler({Exception.class})    //申明捕获哪个异常类
    public ResponseResultVO globalExceptionHandler(Exception e) {
        this.logger.error(e.getMessage(), e);
        return new ResponseResultUtil().error(ResponseCodeEnum.OPERATE_FAIL);
    }

    @ExceptionHandler({BaseBusinessException.class})
    public ResponseResultVO BusinessExceptionHandler(BaseBusinessException e) {
        this.logger.error(e.toString());
        return new ResponseResultUtil().error(e.getCode(), e.getMessage());
    }
}
